import { api } from '@/utils/request'
import type { 
  Comment, 
  CommentPageParams,
  CommentRequest,
  CommentTree,
  CommentStatistics,
  CommentStatisticsParams,
  DailyCommentStatistics,
  PageResult,
  ApiResponse
} from '@/types'

/**
 * 评论管理API服务
 * 按照接口文档规范设计，API路径为：/circle/api-admin/sComment/[action]
 */
export class CommentService {
  /**
   * 分页查询评论列表
   * POST /circle/api-admin/sComment/page
   */
  static async getCommentPage(params: CommentPageParams): Promise<PageResult<Comment>> {
    const response = await api.post<PageResult<Comment>>('/circle/api-admin/sComment/page', params)
    return response.data
  }

  /**
   * 获取评论详情
   * GET /circle/api-admin/sComment/get/{id}
   */
  static async getCommentDetail(id: number): Promise<Comment> {
    const response = await api.get<Comment>(`/circle/api-admin/sComment/get/${id}`)
    return response.data
  }

  /**
   * 删除评论
   * DELETE /circle/api-admin/sComment/delete/{id}
   */
  static async deleteComment(id: number): Promise<boolean> {
    const response = await api.delete<boolean>(`/circle/api-admin/sComment/delete/${id}`)
    return response.data
  }

  /**
   * 获取树形评论
   * GET /circle/api-admin/sComment/tree
   */
  static async getCommentTree(params: {
    sourceType: string,
    sourceId: number,
    page?: number,
    pageSize?: number
  }): Promise<CommentTree> {
    const { sourceType, sourceId, page = 1, pageSize = 20 } = params
    const response = await api.get<CommentTree>(
      `/circle/api-admin/sComment/tree?sourceType=${sourceType}&sourceId=${sourceId}&page=${page}&pageSize=${pageSize}`
    )
    return response.data
  }

  /**
   * 获取评论数据统计
   * GET /circle/api-admin/sComment/countByCondition
   */
  static async getCommentStatistics(params: CommentStatisticsParams): Promise<CommentStatistics> {
    const response = await api.post<CommentStatistics>('/circle/api-admin/sComment/countByCondition', params)
    return response.data
  }

  /**
   * 获取过去一周内每天的评论数 (前端绘制折线图)
   * GET /circle/api-admin/sComment/daily-statistics
   */
  static async getDailyStatistics(): Promise<DailyCommentStatistics[]> {
    const response = await api.get<DailyCommentStatistics[]>('/circle/api-admin/sComment/daily-statistics')
    return response.data
  }
} 